home *** CD-ROM | disk | FTP | other *** search
- /* time() */
- /* This function performs a system function call to get the system */
- /* time, and returns a formattted string via the pointer `ptr'. */
-
- time(ptr, mode)
- char *ptr;
- int mode;
- #define GET_TIME 0x2C
- #define byte char
- #define ONE 1
- #define TWO 2
- #define THREE 3
- #define FOUR 4
- #define FIVE 5
- #define SIX 6
- #define SEVEN 7
-
- {
-
- int hold_yr;
- struct XREG {short ax, bx, cx, dx, si, di;};
- struct HREG {byte al, ah, bl, bh, cl, ch, dl, dh;};
- union REGS {
- struct XREG x;
- struct HREG h;
- } inregs, outregs;
-
- struct dt {
- short hour;
- short minute;
- short second;
- short hundred;
- char *ampm;
- };
-
-
- static char *name[] = {
- "AM", "PM"
- };
-
- struct dt pdate;
-
- inregs.h.ah = GET_TIME;
- inregs.h.al = 0;
- intdos(&inregs, &outregs);
-
- pdate.hour = outregs.h.ch;
- pdate.minute = outregs.h.cl;
- pdate.second = outregs.h.dh;
- pdate.hundred= outregs.h.dl;
-
- if (pdate.hour >= 12) {
- pdate.hour -= 12;
- pdate.ampm = name[1];
- if (pdate.hour < 1)
- pdate.hour = 12;
- } else {
- pdate.ampm = name[0];
- if (pdate.hour < 1)
- pdate.hour = 12;
- }
-
- switch (mode) {
- case ONE:
- sprintf(ptr, "%02d%02d%02d",pdate.hour,pdate.minute,pdate.second);
- break;
- case TWO:
- sprintf(ptr,"%02d:%02d:%02d",pdate.hour,pdate.minute,pdate.second);
- break;
- case THREE:
- sprintf(ptr, "%02d%02d%02d%02d", pdate.hour, pdate.minute,
- pdate.second, pdate.hundred);
- break;
- case FOUR:
- sprintf(ptr, "%02d:%02d:%02d.%02d", pdate.hour, pdate.minute,
- pdate.second, pdate.hundred);
- break;
- case FIVE:
- sprintf(ptr, "%02d:%02d", pdate.hour, pdate.minute);
- break;
- case SIX:
- sprintf(ptr, "%02d:%02d:%02d %s", pdate.hour, pdate.minute,
- pdate.second, pdate.ampm);
- break;
- case SEVEN:
- sprintf(ptr, "%02d:%02d %s", pdate.hour, pdate.minute, pdate.ampm);
- break;
- default:
- break;
- }
- }